package com.pc.store.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*定义一个拦截器*/
public class Logininterceptor implements HandlerInterceptor {

    /*检测全局session对象中是否有uid数据,如果有则放行,如果没有重定向到登录界面*/
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object obj = request.getSession().getAttribute("uid");
        if (obj == null) {/*null则说明用户没有登陆过系统,重定向到login.html*/
            response.sendRedirect("/web/login.html");
            /*结束后续的调用*/
            return false;
        }
        /*请求放行*/
        return true;
    }
}
